var onlineRecordCtrl  = new XFApp.client();
$.views.converters({
	subString : function(val){
		return onlineRecordCtrl.subString(val,7);
	},
	
	ftime : function (val){		
		return onlineRecordCtrl.formateTime(val);
	},

    formatDate : function(val){
    	var date = new Date(val);
    	return date.format("yyyy-MM-dd hh:mm:ss");
    },
	
	fapproveStatus : function(value) {
		if(!value){
			return "";
		}
		for(index in approveStates){
			var approveState = approveStates[index];
			if(approveState.dictCode == value){
				return approveState.dictName;
			}
		}
		return  "未知类型("+value+")";
	},
	
});


XFApp.client.prototype.onlineRecord = {
		successCode : "10000",	
		onlineRecordPage : null,
		checkVal :"",
		showId : null,
		downloadUrl: basePath+"/fileDownload/download?fileType=file&url="+remoteRes,
		urlItems : {
			initListURL: basePath+"/onlineRecord/init",
			showDetailURL:basePath+"/onlineRecord/showDetail",
		},
		
		fapproveStatus : function(value) {
			if(!value){
				return "";
			}
			for(index in approveStates){
				var approveState = approveStates[index];
				if(approveState.dictCode == value){
					return approveState.dictName;
				}
			}
			return  "未知类型("+value+")";
		},
		
		//显示详细
		showDetail : function(id){
			_this = this;
			_this.showId = id ;
			_this.detail(id);			
		},
		
		detail : function (id){			
			_this = this;		
			var params = {					
					id : id 
			};
			
			$.ajax({
				url :_this.urlItems.showDetailURL,
				data : params,
				dataType : "json",
				type : 'post',
				success : function(data) {
					if(data.code == _this.successCode){						
						$("#online_modal").modal();
						$("#dt_companyName").text(data.result.companyName);
						$("#dt_companyAddr").text(data.result.companyAddr);
						$("#dt_contact").text(data.result.contact);
						$("#dt_tel").text(data.result.tel);
						$("#dt_applyRemark").text(data.result.applyRemark);						
						$("#dt_replyRemark").text(data.result.replyRemark);
						$("#dt_approveState").text(_this.fapproveStatus(data.result.approveState));
						var applyFilePath = _this.downloadUrl+data.result.applyFilePath;
						var companyFilePath = _this.downloadUrl+data.result.companyFilePath;
						$("#dt_applyFilePath").attr('href',applyFilePath);	
						$("#dt_companyFilePath").attr('href',companyFilePath);	
		        	}else{		        		
		        		window.webDialogUtil.alert("提示",data.msg); 
		        	}
				}
			});			
		},
		
		
		
		load : function (){
			
            _this = this;
			var onlineRecordVo = {
					companyName : $("#companyName").val(),
					approveState:type
			}
			
			if(!!_this.onlineRecordPage){
				_this.onlineRecordPage.page("remote",0,onlineRecordVo);
			}else{
				_this.onlineRecordPage = $("#page").page({
				pageSize : 10,
				remote: {
					url: _this.urlItems.initListURL,
			        params: onlineRecordVo, 
			        success: function (data, pageIndex) {
			        	if(data.code==_this.successCode){
			        		if(null == data 
									|| null == data.result 
										|| null == data.result.itemList
											|| data.result.itemList.length < 1){
			        			$("#data_grid").html('<tr><td align="center" colspan="11">暂无数据</td></tr>');
			        		}else{
			        			$("#data_grid").html($("#dataTmp").render(data.result.itemList));
			        		}
			        		
			        	}else{
			        		window.webDialogUtil.alert("提示","数据查询失败!");
			        	}
			        },
			        error : function(){
			        	window.webDialogUtil.alert("提示","数据查询失败!");
			        }
				},
				firstBtnText : '首页',
				lastBtnText : '尾页',
				prevBtnText : '上一页',
				nextBtnText : '下一页',
				showInfo : true,
				showJump : true,
				jumpBtnText : '跳转',
				showPageSizes : true,
				infoFormat : '共{pageCount}页'
			});	
		   }			
		},		
		
		event : function(){
			_this = this;
			
			$("#btnSearch").on("click",function(){
				_this.load();
			});
			
			$("#xClose").on("click",function(){
				$("#online_modal").hide();
			});
			$("#btnClose").on("click",function(){
				$("#online_modal").hide();
			});			
	
		},
		
		
};


$(function(){
	onlineRecordCtrl.onlineRecord.load();
	onlineRecordCtrl.onlineRecord.event();
});